/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hibernate.dao;

import hibernate.entity.Conversations;
import hibernate.entity.Accounts;
import hibernate.entity.MessageConversations;
import hibernate.entity.Entities;

/**
 *
 * @author NDH
 */
public class ConverDAO extends AbstractDAO {

    public int create(Conversations cs) {
        try {
            tx = session.beginTransaction();
            session.save(cs);
            tx.commit();
            return 1;
        } catch (Exception e) {
            return -1;
        }
    }
    
    public int getMaxOrderNo(Conversations con){
        query = session.createQuery("select max(mc.orderNumber) from MessageConversation  mc with "
                + "mc.converId =:id");
        query.setParameter("id", con.getConverId());
        try {
             return Integer.parseInt(query.list().get(0).toString());
        } catch (Exception e) {
            return -1;
        }
       
    }
    
//    public Conversations readBy(Logins login, Messages mes){
//        query  = session.createQuery("from Conversations c join c.messageConversations mc where mc.messages = :mesID "
//                 + " and mc.receiver = :loginID");
//         query.setParameter("mesID", mes);
//         query.setParameter("loginID", receiver);
//         try {
//            return (MessageConversation) query.list().get(0);
//         } catch (Exception e) {
//             return null;
//         }
//    }
   
}
